package com.jxc.action.kcgl;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.jxc.action.BaseAction;
import com.jxc.dao.BaseDaoI;
import com.jxc.model.po.Transferlist;
import com.jxc.model.po.TransferlistItem;
import com.jxc.model.vo.Json;
import com.jxc.model.vo.VTransferlistItem;
import com.jxc.service.TransferlistItemServiceI;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 库存调拨明细
 * 
 * @author Tino
 * 
 */
@Namespace("/kcgl")
@Action(value = "goodsTransferItemAction", results = { @Result(name = "goodsTransferItemAdd", location = "/amountRelate/goodsTransferItemAdd.jsp"),
		@Result(name = "goodsTransferItemEdit", location = "/amountRelate/goodsTransferItemEdit.jsp") })
public class GoodsTransferItemAction extends BaseAction implements ModelDriven<VTransferlistItem> {
	private final static Logger logger = Logger.getLogger(GoodsTransferItemAction.class);

	private VTransferlistItem model = new VTransferlistItem();

	@Autowired
	private TransferlistItemServiceI transferlistItemService;
	@Autowired
	private BaseDaoI<Transferlist> Itemdao;

	public void datagrid() {
		
	}

	public String goodsTransferItemAdd() {
		return "goodsTransferItemAdd";
	}

	public String goodsTransferItemEdit() {
		try {
			this.getRequest().setAttribute("id", model.getId());
			Transferlist tr = Itemdao.get(Transferlist.class,model.getId());
			this.getRequest().setAttribute("IsInConfirm", tr.getIsInConfirm());
			this.getRequest().setAttribute("IsOutConfirm",tr.getIsOutConfirm());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "goodsTransferItemEdit";
	}

	@Override
	public VTransferlistItem getModel() {
		return model;
	}
	public void delete() {
		// TODO 判断要删除的调拔单中是否已经确认过，只有未确认过的调拔单才能删除
		Json j = new Json();
		transferlistItemService.delete(model.getIds());
		j.setSuccess(true);
		j.setMsg("删除成功!");
		super.writeJson(j);
	}
}
